/*
 * #%L
 * SwiftUICommonUtilities
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2012 Linkwithweb
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
/**
 * 
 */
package com.linkwithweb.products.swiftui.dataobject;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

/**
 * DROP TABLE IF EXISTS `automata`.`frm_table`;
 * CREATE TABLE `automata`.`frm_table` (
 * `TABLE_KEY` int(10) unsigned NOT NULL AUTO_INCREMENT,
 * `TABLE_ID` varchar(45) DEFAULT NULL,
 * `TABLE_NAME` varchar(45) DEFAULT NULL,
 * `ENTITY_ID` varchar(45) DEFAULT NULL,
 * `TABLE_TYPE` varchar(45) DEFAULT 'SQL/TABLE',
 * `TABLE_SCHEMA` varchar(45) DEFAULT NULL,
 * `TABLE_SQL` varchar(45) DEFAULT NULL,
 * `IS_ACTIVE` tinyint(1) NOT NULL,
 * `IDENTIFIER` varchar(45) DEFAULT NULL,
 * `IDENTIFIER_ROLE` varchar(45) DEFAULT NULL,
 * `CREATED_BY` int(10) unsigned NOT NULL,
 * `CREATED_DATE` datetime NOT NULL,
 * `MODIFIED_BY` int(10) unsigned NOT NULL,
 * `MODIFIED_DATE` datetime NOT NULL,
 * `TABLE_PRIMARY_KEY_COLUMN` varchar(45) DEFAULT NULL,
 * PRIMARY KEY (`TABLE_KEY`)
 * ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
 * 
 * @author ashwin kumar
 * 
 */
public class FrameworkTable extends BaseDataObject {

	private long tableKey = -1;
	private String tableId = "";
	private String tableName = "";
	private String entityId = "";
	private String tableType = "";
	private String tableSchema = "";
	private String tableSQL = "";
	private String primaryKeyColumn = "";
	List<String> primaryKeyColumns = new ArrayList<String>();

	/**
	 * @return the tableKey
	 */
	public long getTableKey() {
		return tableKey;
	}

	/**
	 * @param tableKey
	 *            the tableKey to set
	 */
	public void setTableKey(long tableKey) {
		this.tableKey = tableKey;
	}

	/**
	 * @return the tableId
	 */
	public String getTableId() {
		return tableId;
	}

	/**
	 * @param tableId
	 *            the tableId to set
	 */
	public void setTableId(String tableId) {
		this.tableId = tableId;
	}

	/**
	 * @return the tableName
	 */
	public String getTableName() {
		return tableName;
	}

	/**
	 * @param tableName
	 *            the tableName to set
	 */
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	/**
	 * @return the entityId
	 */
	public String getEntityId() {
		return entityId;
	}

	/**
	 * @param entityId
	 *            the entityId to set
	 */
	public void setEntityId(String entityId) {
		this.entityId = entityId;
	}

	/**
	 * @return the tableType
	 */
	public String getTableType() {
		return tableType;
	}

	/**
	 * @param tableType
	 *            the tableType to set
	 */
	public void setTableType(String tableType) {
		this.tableType = tableType;
	}

	/**
	 * @return the tableSchema
	 */
	public String getTableSchema() {
		return tableSchema;
	}

	/**
	 * @param tableSchema
	 *            the tableSchema to set
	 */
	public void setTableSchema(String tableSchema) {
		this.tableSchema = tableSchema;
	}

	/**
	 * @return the tableSQL
	 */
	public String getTableSQL() {
		return tableSQL;
	}

	/**
	 * @param tableSQL
	 *            the tableSQL to set
	 */
	public void setTableSQL(String tableSQL) {
		this.tableSQL = tableSQL;
	}

	/**
	 * @return the primaryKeyColumn
	 */
	public String getPrimaryKeyColumn() {
		return primaryKeyColumn;
	}

	/**
	 * @param primaryKeyColumn
	 *            the primaryKeyColumn to set
	 */
	public void setPrimaryKeyColumn(String primaryKeyColumn) {
		this.primaryKeyColumn = primaryKeyColumn;
		if (StringUtils.isNotBlank(primaryKeyColumn) && StringUtils.containsIgnoreCase(primaryKeyColumn, ",")) {
			String[] primaryColumns = primaryKeyColumn.split(",");
			for (String primaryColumn : primaryColumns) {
				if (!getPrimaryKeyColumns().contains(primaryColumn))
					getPrimaryKeyColumns().add(primaryColumn);
			}
		} else {
			if (!getPrimaryKeyColumns().contains(primaryKeyColumn))
				getPrimaryKeyColumns().add(primaryKeyColumn);
		}
	}

	/**
	 * @return the primaryKeyColumns
	 */
	public List<String> getPrimaryKeyColumns() {
		return primaryKeyColumns;
	}

	/**
	 * @param primaryKeyColumns
	 *            the primaryKeyColumns to set
	 */
	public void setPrimaryKeyColumns(List<String> primaryKeyColumns) {
		this.primaryKeyColumns = primaryKeyColumns;
	}

}
